using System;
using System.Drawing;

namespace DslCrossModelFramework.NameResolution {
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
    public class ModelElementNameResolutionAttribute : Attribute {
        private readonly Type nameResolver;

        /// <summary>
        /// Gets the name resolver.
        /// </summary>
        /// <value>The name resolver.</value>
        public Type NameResolver {
            get { return nameResolver;}
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelElementNameResolutionAttribute"/> class.
        /// </summary>
        /// <param name="nameResolver">The name resolver.</param>
        public ModelElementNameResolutionAttribute(Type nameResolver) {
            this.nameResolver = nameResolver;
            if(nameResolver.GetInterface(typeof(IModelElementNameResolver).FullName) == null) {
                throw new ArgumentException("Type must be a subclass of IModelElementNameResolver", "nameResolver");
            }
        }

        private string scope = string.Empty;
        /// <summary>
        /// Gets or sets the scope. 
        /// This can be used to enable alternative name representations of a model element depending on the use case.
        /// </summary>
        /// <value>The scope.</value>
        public string Scope {
            get { return scope;}
            set { scope = value;}
        }

        internal IModelElementNameResolver GetResolver() {
            return this.NameResolver.GetConstructor(new Type[] {}).Invoke(null) as IModelElementNameResolver;
        }
    }
}